package org.example;

public class Test2 {
    //leetcode 674 最长连续递增子序列 https://leetcode.cn/problems/longest-continuous-increasing-subsequence/description/

    /**
     * 贪心
     * @param nums
     * @return
     */
    public int findLengthOfLCIS(int[] nums) {
        int ret = 1,len = 1, n = nums.length;
        for (int i = 1; i < n; i++) {
            if (nums[i] > nums[i-1]) {
                len++;
            }else {
                ret = Math.max(ret,len);
                len = 1;
            }
        }
        ret = Math.max(ret,len);
        return ret;
    }

    /**
     * 动态规划
     * @param nums
     * @return
     */
    public int findLengthOfLCIS1(int[] nums) {
        int n = nums.length, ret = 1;
        int[] dp = new int[n];
        dp[0] = 1;
        for (int i = 1; i < n; i++) {
            dp[i] = nums[i] > nums[i-1] ? dp[i-1] + 1 : 1;
            ret = Math.max(ret,dp[i]);
        }
        return ret;
    }

    /**
     * dp优化
     * @param nums
     * @return
     */
    public int findLengthOfLCIS2(int[] nums) {
        int n = nums.length, ret = 1;
        int prev = 1, cur = 1;;
        for (int i = 1; i < n; i++) {
            cur = nums[i] > nums[i-1] ? prev + 1 : 1;
            prev = cur;
            ret = Math.max(ret,cur);
        }
        return ret;
    }
}
